new Vue({
  el: "#app",
  data() {
    return {
      form: {
        SQLSerialNumber: "P_business_category",
        PaginationNumber: 1, //页数
        RowAmount: 15, //每页数据条数
        Category_Name: "",
        Condition: "",
        ExtensionCondition: "",
      },
      total: 0,
      tableData: [], //表格数据
    };
  },
  mounted() {
    this.getList(); //前端分页
  },
  methods: {
    getList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "business_category", //表名
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result);
          _this.tableData = Result;
          //   that.total = Result.TotalRows;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form);
    },
    Add() {
      window.location.href = "./add.html";
    },
    handleSizeChange(val) {
      this.form.PaginationNumber = 1;
      this.form.RowAmount = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.PaginationNumber = val;
      this.getList(this.form);
    },
    // getList(form) {//换页方法
    //     const that = this
    //     let data = deepClone(form);
    //     data.Condition = window.btoa(unescape(encodeURIComponent("%"+data.Category_Name+"%")))
    //     $.ajax({
    //         headers:requestHeaders(),
    //         url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
    //         type: 'POST',
    //         data,
    //         success: function (Result) {
    //             that.tableData = Result.Rows;
    //             that.total = Result.TotalRows;
    //         },
    //         complete: function (XMLHttpRequest) {
    //             requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
    //         },
    //         dataType: "json"
    //     });
    // },
    handleDelete(index, row) {
      const _this = this;
      console.log(index, row);
      row.Row_Status = "1";
      console.log(row);
      delete row.Operation_Datetime;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_business_category = new Object();
      lJSONObject_business_category.business_category = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Modify = lJSONObject_business_category;
      console.log(lJSONObject_DataSet);

      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            _this.tableData.splice(index, 1);
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    Edit(row) {
      console.log(row);
      let Category_SerialNumber = row.Category_SerialNumber;
      sessionStorage.setItem("Category_SerialNumber", Category_SerialNumber);
      window.location.href =
        "./edit.html?Category_SerialNumber=" + Category_SerialNumber;
    },
    // Remove(row) {
    //     const that = this
    //     this.$confirm('警告！此操作将删除该类别, 是否继续?', '提示', {
    //         confirmButtonText: '确定',
    //         cancelButtonText: '取消',
    //         type: 'warning',
    //     }).then(() => {
    //         row.Row_Status = '1';
    //         $.ajax({
    //             headers:requestHeaders(),
    //             url: `${BASE_URL2}/generalBusiness/generalSave`,
    //             type: 'POST',
    //             data: {
    //                 Data: JSON.stringify({ Modify: { business_category: [row] } })
    //             },
    //             success: function (res) {
    //                 if (res.Status === 'success') {
    //                     that.$message({
    //                         type: 'success',
    //                         message: '删除成功!'
    //                     });
    //                     that.getList(that.form);
    //                 } else {
    //                     that.$message.error("删除失败，请稍后再试")
    //                 }
    //             },
    //             complete: function (XMLHttpRequest) {
    //                 that.loading = false
    //                 requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
    //             },
    //             dataType: "json"
    //         })
    //     }).catch(() => {});
    // }
  },
});
